/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package avl.sv.shared.Annotations;

import java.awt.Color;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.logging.Logger;
import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;

/**
 *
 * @author benbryan
 */
public class Annotation extends DefaultMutableTreeTableNode implements Serializable  {

    public ArrayList<Attributes> attributes;
    public int id, lineColor, type;
    public String name;
    public boolean visible, selected;
    
    public static Annotation createDefault(){
        Annotation anno = new Annotation();
        anno.attributes = new ArrayList<>();
        anno.id = 0; 
        anno.lineColor = Color.green.getRGB();
        anno.type = 0;
        anno.name = "New Annotation set";
        anno.visible = true;
        anno.selected = true;
        return anno;
    }
    
    public ArrayList<ROI> getRois() {       
        if (children == null){
            return new ArrayList<>();
        }
        ArrayList<ROI> rois = new ArrayList<>();
        for (Object r:children){
            if (r instanceof ROI){
                rois.add((ROI)r);
            }
        }
        
        return rois;
    }

    @Override
    public String toString() {
        return String.valueOf(id)+ ": " + name;
    }

    @Override
    public void setUserObject(Object userObject) {
        if (String.class.equals(userObject.getClass())){
            String newString = (String) userObject;
            if (newString.contains(":")) {
                newString = newString.substring(newString.lastIndexOf(":") + 1);
            }
            newString = newString.trim();
            name = newString;

        } else {
            super.setUserObject(toString());
        }
    }
    
}


